<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		
		<link rel="stylesheet" href="./assets/styles/ui-lightness/ui.all.css" type="text/css" />
		
		<link rel="stylesheet" href="./assets/styles/ui-lightness/jquery-ui-1.7.3.custom.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />
		
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
		
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<script type="text/javascript" src="./tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript" src="./assets/scripts/editor.js"></script>

		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>

		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");

			$('#btn-add').click(function(){
				var weekid = $("#matrix_cd").val() ;
				if (weekid.length == 0){
					alert("週を選択してください");
					return false;
				 }
				var patternid = $("#pattern_cd").val() ;
				if (patternid.length == 0){
					 alert("新聞紙を選択してください");
					 return false;
				 } else {
					var myDate = new Date();
					var nowtime =  myDate.getTime();
					 $.get("ajax_dnpw_area_tab_exist.php",{ w : weekid, p : patternid, t : nowtime }, function(data){
						var tabCnt = 1 * data;
						 if ( tabCnt ==1 ) {
							if( confirm('該当週のデータは既に存在します、コピーしてもよろしいですか？') ){
								document.fm.mode.value = 'update';
								document.fm.submit();;
							}else{
								return false;
							}
						 }
						if  ( tabCnt == 0 ) {
							alert("該当週のテーブルは存在しない。\r\nコピー前にテーブルを作成してください");
							return false;
						 }
						if  ( tabCnt == 100 ) {
							document.fm.mode.value = 'update';
							document.fm.submit();;
						 }
					});
					//document.fm.mode.value = 'update';
					//document.fm.submit();;
				 }
			});
			$('#year4').change(function(){
				var year4 = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				$.get("mmap_week_ajax.php",{ y: year4,t : nowtime }, function(data){
					$("#matrix_cd").children().remove();
					$("#matrix_cd").append( data ); 
				});
			});	
		});
		</script>
		<link rel="stylesheet" type="text/css" href="./assets/styles/tablesorter.css" />
		<script type="text/javascript" src="./assets/scripts/tablesorter.js"></script>
	</head>
	<body id="">
{{$menu}}
{{$logout}}
		<div id="container"><div class="wrapper">
			<h2>地域広告情報登録 </h2>
			<ul class="submenu clearfix">
				<li><a href="ddnpwarea_index.php">地域広告情報一覧．更新</a></li>
				 <li>地域広告情報登録 </li>
				 <li><a href="ddnparea_index.php">DNPエリアマスタ</a></li>
			</ul>
			<h3>地域広告情報登録</h3>
			{{$mesg}}
			<form name="fm" id="fm" method="get" action="ddnpwarea_update.php" >
				<input type="hidden" name="page" />
				<table class="formTable">
					<tbody><tr>
						<th>※配布日</th>
							<td>
{{ html_options id='year4' name='year4' options=$year4 selected=$forms.year4 }} 年{{ $err.year4 }}&nbsp;&nbsp;&nbsp;
{{ html_options id='matrix_cd' name='matrix_cd' options=$week  selected=$forms.matrix_cd }}{{ $err.matrix_cd }}
							</td>
						</tr><tr>
							<th>※新聞紙名</th>
							<td>
								{{ html_options id='pattern_cd' name='pattern_cd' options=$pattern selected=$forms.pattern_cd }}
							</td>
						</tr>
					</tbody>
				</table>
				<p class="button" style="text-align:center">
					<button type="button" id="btn-add"><span>登録</span></button>
				</p>
				<input type="hidden" name="mode" />
			</form>
		
		</div></div>
		{{ $footer }}
	</body>
</html>